"""Add cascade delete for project and data

Revision ID: dce162c0888d
Revises: 47acc5be400c
Create Date: 2025-03-21 12:03:44.737066

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = 'dce162c0888d'
down_revision: Union[str, None] = '47acc5be400c'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('data', 'project_id',
               existing_type=mysql.INTEGER(),
               nullable=False)
    op.drop_constraint('data_ibfk_1', 'data', type_='foreignkey')
    op.create_foreign_key(None, 'data', 'project', ['project_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'data', type_='foreignkey')
    op.create_foreign_key('data_ibfk_1', 'data', 'project', ['project_id'], ['id'])
    op.alter_column('data', 'project_id',
               existing_type=mysql.INTEGER(),
               nullable=True)
    # ### end Alembic commands ###
